package com.fingard.dsp.bank.directbank.bochk01;

import java.sql.Connection;
import java.util.Date;
import java.util.Map;
import java.util.UUID;

import com.fingard.FGBiz;
import com.fingard.constant.Format;
import com.fingard.db.JDBCHelper;
import com.fingard.dsp.bank.directbank.bankInterface.ISinglePay;
import com.fingard.dsp.bank.reqrespobj.single.*;
import com.fingard.dsp.bank.reqrespobj.single.detail.RetAtsSglDetail;
import com.fingard.text.StringHelper;
import com.fingard.xml.XElement;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;

public class BOCHK01SinglePay extends BOCHK01Base implements ISinglePay{
    private static final String INSERTSEQ = "INSERT INTO REQSEQIDMAPPING(URID,BANKCODE,TRANSDATE,REQSEQID,BANKREQSEQID) values (?,?,?,?,?);";
    private static final String SELECTSEQ = "SELECT BANKREQSEQID FROM REQSEQIDMAPPING WHERE REQSEQID=? AND BANKCODE=?;";

    @Override
    public RetAtsSingle d_1908_SglPay(ReqSingle p_req1908) throws Exception {
        RetAtsSingle retAtsSingle = new RetAtsSingle(p_req1908.reqHeader);
        RetAtsSglDetail detail = new RetAtsSglDetail();
        try{
            if ("1".equals(p_req1908.singleDetail.sameBnk)) {
                detail = internalTrans(p_req1908);
            } else if ("1".equals(p_req1908.singleDetail.sameCity)) {
                detail = localBankTrans(p_req1908);
            } else {
                detail = teleTransfer(p_req1908);
            }
        }catch (Exception e){
            detail.respCode = "-1";
            detail.respInfo = e.getMessage();
            e.printStackTrace();
            WriteBankLogLn("付款出现异常:"+e);
        }
        retAtsSingle.writeRetDetail(detail);
        return retAtsSingle;
    }

    /**
     * 6.2.8	同行转账 (TransferREQ - InternalTrans)
     *
     * @param p_req1908
     * @return
     */
    private RetAtsSglDetail internalTrans(ReqSingle p_req1908) throws Exception {
        RetAtsSglDetail tmpRetDetail = new RetAtsSglDetail();
        Connection conn= FGBiz.getLocalDbConn();
        try {
            //赋值通用参数
            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
            BOCHK01Header tmpHeader = new BOCHK01Header();
            tmpHeader.packageId = getQryTransID2() + "0";
            //记录ats支付流水号对应的银行支付流水号，供查询状态接口使用
            String uuid = UUID.randomUUID().toString().replaceAll("-", "");
            JDBCHelper.update(conn, INSERTSEQ, new Object[]{uuid, p_req1908.reqHeader.bankCode, Format.Date8Format.format(new Date()), p_req1908.singleDetail.askNumber, tmpHeader.packageId});
            writeCommonHeader(xmlWriter, tmpHeader);
            xmlWriter.writeStartElement("TransferREQ");
            xmlWriter.writeElementString("DebitAcctNo","");//付款账号
            xmlWriter.writeElementString("DebitCur","");//付款币种
            xmlWriter.writeElementAttribute("Requests", "noOfRecord","1");
            xmlWriter.writeStartElement("Record");
            XElement tmpTransXElement = new XElement("InternalTrans", "");//����^
            tmpTransXElement.addChild(new XElement("DDebitAcctNo", p_req1908.singleDetail.payAct));//
            if(!"1".equals(p_req1908.singleDetail.payCur) || !"1".equals(p_req1908.singleDetail.recCur)){//必须为RMB转账业务，非RMB转账业务走ForeignCurrSinglePay
                tmpRetDetail=new RetAtsSglDetail();
                tmpRetDetail.respCode = "-1";
                tmpRetDetail.respInfo = "币种非人民币，请使用其它通道";
                return tmpRetDetail;
            }
            tmpTransXElement.addChild(new XElement("DDebitCur", convertCurToBank(p_req1908.singleDetail.payCur)));//付款币种
            tmpTransXElement.addChild(new XElement("DebitAmt", ""));//付款金额
            tmpTransXElement.addChild(new XElement("BeneAcctNo", p_req1908.singleDetail.recAct));//收款人账号
            tmpTransXElement.addChild(new XElement("BeneAcctName", p_req1908.singleDetail.recName));//收款人名称/地址
            tmpTransXElement.addChild(new XElement("PaymentCur", convertCurToBank(p_req1908.singleDetail.payCur)));//收款人币种
            tmpTransXElement.addChild(new XElement("EquvAmt", p_req1908.singleDetail.payAmount));//汇款金额
            tmpTransXElement.addChild(new XElement("CustRef", p_req1908.singleDetail.askNumber));//支付流水号
            tmpTransXElement.addChild(new XElement("ExContract", ""));//合约汇率
            tmpTransXElement.addChild(new XElement("ValueDate", ""));//生效日期
            nodeAnalysis(p_req1908.singleDetail.srcXElement, tmpTransXElement, getCharset());
            xmlWriter.writeXElement(tmpTransXElement);
            xmlWriter.writeEndDocument();
            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String txStatus = tmpBkReader.getFirstText("/BOCHKB2E/Head/TxStatus");
                    if ("S".equals(txStatus) || "R".equals(txStatus) || "F".equals(txStatus)) {
                        tmpRetDetail.respCode = "0";
                        tmpRetDetail.respInfo = tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorDesc");
                        tmpRetDetail.reqSeqID = p_req1908.singleDetail.askNumber;
                        if ("F".equals(txStatus)) {
                            if (tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorCode") != null) {
                                tmpRetDetail.transState = txStatus + "+" + tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorCode");
                                tmpRetDetail.payInfoCode = tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorCode");
                            }
                        } else if ("R".equals(txStatus)) {
                            if (tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/InternalTrans/RecordErrorCode") != null) {
                                tmpRetDetail.transState = txStatus + "+" + tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/InternalTrans/RecordStatus");
                                tmpRetDetail.payInfoCode = tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/InternalTrans/RecordErrorCode");
                                tmpRetDetail.respInfo = tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/InternalTrans/RecordErrorDesc");
                            } else {
                                tmpRetDetail.transState = txStatus + "+" + tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorCode");
                                tmpRetDetail.payInfoCode = tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorCode");
                            }
                        } else {
                            if (tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/InternalTrans/RecordErrorDesc") != null) {
                                tmpRetDetail.respInfo = tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/InternalTrans/RecordErrorDesc");
                            }
                            tmpRetDetail.transState = txStatus + "+" + tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/InternalTrans/RecordStatus");
                            if (tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/InternalTrans/RecordErrorCode") != null) {
                                tmpRetDetail.payInfoCode = tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/InternalTrans/RecordErrorCode");
                            } else {
                                tmpRetDetail.payInfoCode = tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/InternalTrans/RecordStatus");
                                tmpRetDetail.respInfo = "提交成功";
                            }
                        }
                    } else {
                        tmpRetDetail.respCode = "-1";
                        tmpRetDetail.respInfo = "错误代码：" + tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorCode") + "，错误信息：" + tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorDesc");
                    }
                } else {
                    tmpRetDetail.respCode = "-1";
                    tmpRetDetail.respInfo = tmpSbMsg.toString();
                }
            } else {
                tmpRetDetail.respCode = "-1";
                tmpRetDetail.respInfo = tmpStrRet[1];
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            tmpRetDetail.respCode = "-1";
            tmpRetDetail.respInfo = ex.getMessage();
        }finally {
            conn.close();
        }
        return tmpRetDetail;
    }

    /**
     * 6.2.9	同城转账走chats (TransferREQ - LocalBankTrans)
     *
     * @param p_req1908
     * @return
     */

    private RetAtsSglDetail localBankTrans(ReqSingle p_req1908) throws Exception {
        RetAtsSglDetail tmpRetDetail = new RetAtsSglDetail();
        Connection conn= FGBiz.getLocalDbConn();
        try {
            //赋值通用参数
            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
            BOCHK01Header tmpHeader = new BOCHK01Header();
            tmpHeader.packageId = getQryTransID2() + "1";
            //记录ats支付流水号对应的银行支付流水号，供查询状态接口使用
            String uuid = UUID.randomUUID().toString().replaceAll("-", "");
            JDBCHelper.update(conn, INSERTSEQ, new Object[]{uuid, p_req1908.reqHeader.bankCode, Format.Date8Format.format(new Date()), p_req1908.singleDetail.askNumber, tmpHeader.packageId});
            writeCommonHeader(xmlWriter, tmpHeader);
            xmlWriter.writeStartElement("TransferREQ");
            xmlWriter.writeElementString("DebitAcctNo","");
            xmlWriter.writeElementString("DebitCur","");
            xmlWriter.writeElementAttribute("Requests","noOfRecord","1");
            XElement tmpRecordXElement = new XElement("Record", "");//
            XElement tmpTransXElement = new XElement("LocalBankTrans", "");//
            tmpTransXElement.addChild(new XElement("DDebitAcctNo", p_req1908.singleDetail.payAct));//付款账号
            tmpTransXElement.addChild(new XElement("DDebitCur", convertCurToBank(p_req1908.singleDetail.payCur)));//付款币种
            tmpTransXElement.addChild(new XElement("DebitAmt", ""));//付款金额
            tmpTransXElement.addChild(new XElement("BeneBankCode", ""));//收款人账户银行代号
            //tmpTransXElement.addChild(new XElement("BeneBankCode", p_req1908.singleDetail.recRTGSCode));//收款人账户银行代号
            String tmpRecAct = p_req1908.singleDetail.recAct;
            /*String tmpBeneNameAddr = "";
            if (StringHelper.hasAnyChar(p_req1908.singleDetail.recAct)) {
                if (p_req1908.singleDetail.recAct.length() > 6) {
                    *//*将客商银行账号前3位与其银行类别编码（RTGS码）进行比对：
                    1)两者相等，则截取掉客商账户前3位
                    2)如果不相等，则不截取*//*
                    String tmpActH3 = p_req1908.singleDetail.recAct.substring(0, 3);
                    if (tmpActH3.equals(p_req1908.singleDetail.recRTGSCode)) {
                        tmpRecAct = tmpRecAct.substring(3);
                    }
                    //对前一步处理后的客商账号前三位进行截取，放入BeneBranchCode字段。
                    String tmpBeneBranchCode = tmpRecAct.substring(0, 3);
                    tmpTransXElement.addChild(new XElement("BeneBranchCode", tmpBeneBranchCode));//收款人賬戶分支行代號
                    tmpRecAct = tmpRecAct.substring(3);
                    //1、	此时受益人银行账户剩余长度<=28，直接写入支付报文的BeneAcctNo字段；
                    if (tmpRecAct.length() <= 28) {
                        tmpTransXElement.addChild(new XElement("BeneAcctNo", tmpRecAct));//收款人账号
                    } else {
                        //2、	受益人银行账户剩余长度>28位时，将前28位写入支付报文BeneAcctNo字段，并且将当前账号（AC NO bank code+branch code+截取剩余部分）写入到BeneNameAddr字段；
                        tmpTransXElement.addChild(new XElement("BeneAcctNo", tmpRecAct.substring(0, 28)));//收款人账号
                        tmpBeneNameAddr = "AC NO " + p_req1908.singleDetail.recRTGSCode + tmpBeneBranchCode + tmpRecAct;
                    }
                } else {//当客商账户<=6位,受益人账号处理逻辑
                    tmpTransXElement.addChild(new XElement("BeneBranchCode", ""));//收款人賬戶分支行代號
                    tmpTransXElement.addChild(new XElement("BeneAcctNo", tmpRecAct));//收款人账号
                    tmpBeneNameAddr = "AC NO " + p_req1908.singleDetail.recRTGSCode + tmpRecAct;
                }
            } else {*/
                tmpTransXElement.addChild(new XElement("BeneBranchCode", ""));//收款人賬戶分支行代號
                tmpTransXElement.addChild(new XElement("BeneAcctNo", ""));//收款人账号
            //}
            XElement tmpBeneNameAddrXE = new XElement("BeneNameAddr", "");//收款人账户地址
            if(StringHelper.hasAnyChar(p_req1908.singleDetail.recName)){
                tmpBeneNameAddrXE.addChild(new XElement("Line",p_req1908.singleDetail.recName));
            }
            if(StringHelper.hasAnyChar(p_req1908.singleDetail.recStandardArea)){
                tmpBeneNameAddrXE.addChild(new XElement("Line",p_req1908.singleDetail.recStandardArea));
            }
            tmpTransXElement.addChild(tmpBeneNameAddrXE);
            tmpTransXElement.addChild(new XElement("PaymentCur", convertCurToBank(p_req1908.singleDetail.recCur)));//收款币种
            tmpTransXElement.addChild(new XElement("EquvAmt", p_req1908.singleDetail.payAmount));//汇款金额
            XElement tmpChargeFromXE = new XElement("ChargeFrom", "");
            XElement tmpChargeFromAcctXE = new XElement("ChargeFromAcct", "");
            tmpChargeFromAcctXE.addChild(new XElement("ChargeAcctNo", p_req1908.singleDetail.payAct));//手续费承担方
            tmpChargeFromAcctXE.addChild(new XElement("ChargeCur", convertCurToBank(p_req1908.singleDetail.payCur)));//手续费币种
            tmpChargeFromAcctXE.addChild(new XElement("ChargeBorneBy", "A"));//费用收取方A汇款人B收款人
            tmpChargeFromXE.addChild(tmpChargeFromAcctXE);
            tmpTransXElement.addChild(tmpChargeFromXE);
            XElement tmpPaymentDetailXE = new XElement("PaymentDetail", "");//附言
            if(StringHelper.hasAnyChar(p_req1908.singleDetail.purpose)){
                tmpPaymentDetailXE.addChild(new XElement("Line",p_req1908.singleDetail.purpose));
            }else {
                tmpPaymentDetailXE.addChild(new XElement("Line",""));
            }
            tmpTransXElement.addChild(tmpPaymentDetailXE);
            tmpTransXElement.addChild(new XElement("CustRef", p_req1908.singleDetail.askNumber));//支付流水号
            tmpTransXElement.addChild(new XElement("ExContract", ""));//汇率合约
            tmpTransXElement.addChild(new XElement("ValueDate", ""));//生效日期
            nodeAnalysis(p_req1908.singleDetail.srcXElement, tmpTransXElement, getCharset());
            tmpRecordXElement.addChild(tmpTransXElement);
            xmlWriter.writeXElement(tmpRecordXElement);
            xmlWriter.writeEndDocument();
            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String txStatus = tmpBkReader.getFirstText("/BOCHKB2E/Head/TxStatus");
                    if ("S".equals(txStatus) || "R".equals(txStatus) || "F".equals(txStatus)) {
                        tmpRetDetail.respCode = "0";
                        tmpRetDetail.respInfo = tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorDesc");
                        tmpRetDetail.reqSeqID = p_req1908.singleDetail.askNumber;
                        if ("F".equals(txStatus)) {
                            if (tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorCode") != null) {
                                tmpRetDetail.transState = txStatus + "+" + tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorCode");
                                tmpRetDetail.payInfoCode = tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorCode");
                            }
                        } else if ("R".equals(txStatus)) {
                            if (tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/LocalBankTrans/RecordErrorCode") != null) {
                                tmpRetDetail.transState = txStatus + "+" + tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/LocalBankTrans/RecordStatus");
                                tmpRetDetail.payInfoCode = tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/LocalBankTrans/RecordErrorCode");
                                tmpRetDetail.respInfo = tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/LocalBankTrans/RecordErrorDesc");
                            } else {
                                tmpRetDetail.transState = txStatus + "+" + tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorCode");
                                tmpRetDetail.payInfoCode = tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorCode");
                            }
                        } else {
                            if (tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/LocalBankTrans/RecordErrorDesc") != null) {
                                tmpRetDetail.respInfo = tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/LocalBankTrans/RecordErrorDesc");
                            }
                            tmpRetDetail.transState = txStatus + "+" + tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/LocalBankTrans/RecordStatus");
                            if (tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/LocalBankTrans/RecordErrorCode") != null) {
                                tmpRetDetail.payInfoCode = tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/LocalBankTrans/RecordErrorCode");
                            } else {
                                tmpRetDetail.payInfoCode = tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/LocalBankTrans/RecordStatus");
                                tmpRetDetail.respInfo = "提交成功";
                            }
                        }
                    } else {
                        tmpRetDetail.respCode = "-1";
                        tmpRetDetail.respInfo = "错误代码：" + tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorCode") + "，错误信息：" + tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorDesc");
                    }
                } else {
                    tmpRetDetail.respCode = "-1";
                    tmpRetDetail.respInfo = tmpSbMsg.toString();
                }
            } else {
                tmpRetDetail.respCode = "-1";
                tmpRetDetail.respInfo = tmpStrRet[1];
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            tmpRetDetail.respCode = "-1";
            tmpRetDetail.respInfo = ex.getMessage();
        }finally {
            conn.close();
        }
        return tmpRetDetail;
    }

    /**
     * 6.2.10 电汇 (TransferREQ - TeleTransfer)
     *
     * @param p_req1908
     * @return
     */
    private RetAtsSglDetail teleTransfer(ReqSingle p_req1908) throws Exception {
        RetAtsSglDetail tmpRetDetail = new RetAtsSglDetail();
        Connection conn= FGBiz.getLocalDbConn();
        try {
            //赋值通用参数
            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
            BOCHK01Header tmpHeader = new BOCHK01Header();
            tmpHeader.packageId = getQryTransID2() + "2";
            //记录ats支付流水号对应的银行支付流水号，供查询状态接口使用
            String uuid = UUID.randomUUID().toString().replaceAll("-", "");
            JDBCHelper.update(conn, INSERTSEQ, new Object[]{uuid, p_req1908.reqHeader.bankCode, Format.Date8Format.format(new Date()), p_req1908.singleDetail.askNumber, tmpHeader.packageId});
            writeCommonHeader(xmlWriter, tmpHeader);
            xmlWriter.writeStartElement("TransferREQ");
            xmlWriter.writeElementString("DebitAcctNo","");
            xmlWriter.writeElementString("DebitCur","");
            xmlWriter.writeElementAttribute("Requests","noOfRecord","1");
            XElement tmpRecordXElement = new XElement("Record", "");
            XElement tmpTransXElement = new XElement("TeleTransfer", "");
            tmpTransXElement.addChild(new XElement("DDebitAcctNo", p_req1908.singleDetail.payAct));//付款账号
            tmpTransXElement.addChild(new XElement("DDebitCur", convertCurToBank(p_req1908.singleDetail.payCur)));//付款币种
            tmpTransXElement.addChild(new XElement("RemitCur", convertCurToBank(p_req1908.singleDetail.payCur)));//收款币种
            tmpTransXElement.addChild(new XElement("RemitAmt", p_req1908.singleDetail.payAmount));//汇款金额
            tmpTransXElement.addChild(new XElement("EquvAmt", ""));//
            XElement tmpChargeFromXE = new XElement("ChargeFrom", "");
            XElement tmpChargeFromAcctXE = new XElement("ChargeFromAcct", "");
            tmpChargeFromAcctXE.addChild(new XElement("ChargeAcctNo", p_req1908.singleDetail.payAct));//手续费账号
            tmpChargeFromAcctXE.addChild(new XElement("ChargeCur", convertCurToBank(p_req1908.singleDetail.payCur)));//手续费币种
            tmpChargeFromAcctXE.addChild(new XElement("ChargeBorneBy", "A"));//手续费方 A汇款人
            tmpChargeFromXE.addChild(tmpChargeFromAcctXE);
            tmpTransXElement.addChild(tmpChargeFromXE);
            //收款银行信息
            if(StringHelper.hasAnyChar(p_req1908.singleDetail.cnapsCode)){
                tmpTransXElement.addChild(new XElement("BeneBankerSwiftCode", p_req1908.singleDetail.recSwiftCode));//收款银行swiftcode
                tmpTransXElement.addChild(new XElement("BeneBankerCountry", convertCountryToBank(p_req1908.singleDetail.recCountry)));//收款银行国家/地区
                XElement tmpBeneBankerNameXE = new XElement("BeneBankerName", "");
                String bankName="";
                if(StringHelper.hasAnyChar(p_req1908.singleDetail.cnapsName)){
                    bankName=p_req1908.singleDetail.cnapsName;
                }else if(StringHelper.hasAnyChar(p_req1908.singleDetail.recBankName)){
                    bankName=p_req1908.singleDetail.recBankName;
                }
                String bankAddr="";
                if(StringHelper.hasAnyChar(p_req1908.singleDetail.recBankAddress)){
                    bankAddr=p_req1908.singleDetail.recBankAddress;
                }else if(StringHelper.hasAnyChar(p_req1908.singleDetail.recNameAddress)){
                    bankAddr=p_req1908.singleDetail.recNameAddress;
                }
                if(StringHelper.isNullOrEmpty(p_req1908.singleDetail.recSwiftCode)){
                    String beneBankerName = bankName + " " + bankAddr;
                    spiltToLine(tmpBeneBankerNameXE, beneBankerName, 3);
                }else {
                    tmpBeneBankerNameXE.addChild(new XElement("Line", ""));//按银行要求Line至少存在一个
                }
                tmpTransXElement.addChild(tmpBeneBankerNameXE);
            }else {
                tmpTransXElement.addChild(new XElement("BeneBankerSwiftCode", p_req1908.singleDetail.recSwiftCode));//收款银行swiftcode
                tmpTransXElement.addChild(new XElement("BeneBankerCountry", convertCountryToBank(p_req1908.singleDetail.recCountry)));
                XElement tmpBeneBankerNameXE = new XElement("BeneBankerName", "");
                tmpBeneBankerNameXE.addChild(new XElement("Line", ""));//按银行要求Line至少存在一个
                tmpTransXElement.addChild(tmpBeneBankerNameXE);
            }
            //清算要求参数
            tmpTransXElement.addChild(new XElement("BeneBankerCountryCodeWords", ""));
            if(StringHelper.hasAnyChar(p_req1908.singleDetail.cnapsCode)){
                tmpTransXElement.addChild(new XElement("CnapsNum", p_req1908.singleDetail.cnapsCode));
            }else {
                tmpTransXElement.addChild(new XElement("CnapsNum", ""));
            }
            tmpTransXElement.addChild(new XElement("RMBRemitTxType", getBankConfig().getMapValueByContainsKey("RMBRemitTxTypeMapping", p_req1908.singleDetail.purpose)));//人民幣匯款交易種類
            tmpTransXElement.addChild(new XElement("RemitBeneAcctNo", p_req1908.singleDetail.recAct));//匯款收款人賬戶號碼
            XElement tmpRemitBeneNameXE = new XElement("RemitBeneName", "");//收款人名称/地址
            if(StringHelper.hasAnyChar(p_req1908.singleDetail.recName)){
                tmpRemitBeneNameXE.addChild(new XElement("Line",p_req1908.singleDetail.recName));
            }
            if(StringHelper.hasAnyChar(p_req1908.singleDetail.recNameAddress)) {
                tmpRemitBeneNameXE.addChild(new XElement("Line",p_req1908.singleDetail.recNameAddress));
            }
            tmpTransXElement.addChild(tmpRemitBeneNameXE);
            /*if (StringHelper.hasAnyChar(p_req1908.singleDetail.recAgtBankName)) {
                tmpTransXElement.addChild(new XElement("BeneBankerAcct", reqForeignCurrSingle.singleDetail.recAgentBnkAct));//代理行�~�
                tmpTransXElement.addChild(new XElement("CorreBeneBankerCountry", convertCountryToBank(reqForeignCurrSingle.singleDetail.recAgentBnkCtryCode)));//代理行��家/地�^
                tmpTransXElement.addChild(new XElement("CorreBeneBankerSwiftCode", reqForeignCurrSingle.singleDetail.recAgentBnkSWIFT));//代理行SWIFT BIC CODE
                XElement tmpCorreBeneBankerXE = new XElement("CorreBeneBanker", "");//代理行名称及地址
                if (StringHelper.isNullOrEmpty(reqForeignCurrSingle.singleDetail.recAgentBnkSWIFT)) {
                    String correBeneBanker = reqForeignCurrSingle.singleDetail.recAgentBnkName + " " + reqForeignCurrSingle.singleDetail.recAgentBnkAddr;
                    spiltToLine(tmpCorreBeneBankerXE, correBeneBanker, 3);
                } else {
                    tmpCorreBeneBankerXE.addChild(new XElement("Line", ""));//按银行要求Line至少存在一个
                }
                tmpTransXElement.addChild(tmpCorreBeneBankerXE);

            } else {*/
            tmpTransXElement.addChild(new XElement("BeneBankerAcct", ""));//代理行�~�
            tmpTransXElement.addChild(new XElement("CorreBeneBankerCountry", ""));//代理行��家/地�^
            tmpTransXElement.addChild(new XElement("CorreBeneBankerSwiftCode", ""));//代理行SWIFT BIC CODE
            XElement tmpCorreBeneBankerXE = new XElement("CorreBeneBanker", "");//代理行名�Q及地址
            tmpCorreBeneBankerXE.addChild(new XElement("Line", ""));//按银行要求Line至少存在一个
            tmpTransXElement.addChild(tmpCorreBeneBankerXE);
            //}

            XElement tmpPaymentDetailXE = new XElement("PaymentDetail", "");//附言
            spiltToLine(tmpPaymentDetailXE, p_req1908.singleDetail.purpose, 4);
            tmpTransXElement.addChild(tmpPaymentDetailXE);

            tmpTransXElement.addChild(new XElement("MessageToBank", ""));//
            tmpTransXElement.addChild(new XElement("CustRef", p_req1908.singleDetail.askNumber));//支付流水号
            String exContract = "";
            tmpTransXElement.addChild(new XElement("ExContract", ""));//汇率合约
            tmpTransXElement.addChild(new XElement("ValueDate", ""));//生效日期
            nodeAnalysis(p_req1908.singleDetail.srcXElement, tmpTransXElement, getCharset());
            tmpRecordXElement.addChild(tmpTransXElement);
            xmlWriter.writeXElement(tmpRecordXElement);
            xmlWriter.writeEndDocument();
            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String txStatus = tmpBkReader.getFirstText("/BOCHKB2E/Head/TxStatus");
                    if ("S".equals(txStatus) || "R".equals(txStatus) || "F".equals(txStatus)) {
                        tmpRetDetail.respCode = "0";
                        tmpRetDetail.respInfo = tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorDesc");
                        tmpRetDetail.reqSeqID = p_req1908.singleDetail.askNumber;
                        if ("F".equals(txStatus)) {
                            if (tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorCode") != null) {
                                tmpRetDetail.transState = txStatus + "+" + tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorCode");
                                tmpRetDetail.payInfoCode = tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorCode");
                            }
                        } else if ("R".equals(txStatus)) {
                            if (tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/TeleTransfer/RecordErrorCode") != null) {
                                tmpRetDetail.transState = txStatus + "+" + tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/TeleTransfer/RecordStatus");
                                tmpRetDetail.payInfoCode = tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/TeleTransfer/RecordErrorCode");
                                tmpRetDetail.respInfo = tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/TeleTransfer/RecordErrorDesc");
                            } else {
                                tmpRetDetail.transState = txStatus + "+" + tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorCode");
                                tmpRetDetail.payInfoCode = tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorCode");
                            }
                        } else {
                            if (tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/TeleTransfer/RecordErrorDesc") != null) {
                                tmpRetDetail.respInfo = tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/TeleTransfer/RecordErrorDesc");
                            }
                            tmpRetDetail.transState = txStatus + "+" + tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/TeleTransfer/RecordStatus");
                            if (tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/TeleTransfer/RecordErrorCode") != null) {
                                tmpRetDetail.payInfoCode = tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/TeleTransfer/RecordErrorCode");
                            } else {
                                tmpRetDetail.payInfoCode = tmpBkReader.getFirstText("/BOCHKB2E/TX/TransferRLY/Requests/Record/TeleTransfer/RecordStatus");
                                tmpRetDetail.respInfo = "提交成功";
                            }
                        }
                    } else {
                        tmpRetDetail.respCode = "-1";
                        tmpRetDetail.respInfo = "错误代码：" + tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorCode") + "，错误信息：" + tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorDesc");
                    }
                } else {
                    tmpRetDetail.respCode = "-1";
                    tmpRetDetail.respInfo = tmpSbMsg.toString();
                }
            } else {
                tmpRetDetail.respCode = "-1";
                tmpRetDetail.respInfo = tmpStrRet[1];
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            tmpRetDetail.respCode = "-1";
            tmpRetDetail.respInfo = ex.getMessage();
        }finally {
            conn.close();
        }
        return tmpRetDetail;
    }


    @Override
    public RetAtsSingle d_1944_QrySglPay(ReqQrySingle p_req1944) throws Exception {
        RetAtsSingle retAts = new RetAtsSingle(p_req1944.reqHeader);
        RetAtsSglDetail tmpRetDetail = new RetAtsSglDetail();
        Connection conn=FGBiz.getLocalDbConn();
        try {
            //String oriSeqID = DirectHelper.getReqSeqIDMapping(reqQryForeignCurrSingle.askNumber);//某位表示具体支付方式 0：�⑴c行�D�~  1：本地�y行�D�~ 2：��R
            XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
            BOCHK01Header tmpHeader = new BOCHK01Header();
            tmpHeader.packageId = getQryTransID();
            writeCommonHeader(xmlWriter, tmpHeader);
            XElement tmpXElement = new XElement("TransferEnquiryREQ", "");
            Map<String, Object> selMap=JDBCHelper.execQuerySingle(conn,SELECTSEQ,new Object[]{p_req1944.askNumber,p_req1944.reqHeader.bankCode});
            if(selMap.size()>0){
                tmpXElement.addChild(new XElement("EnqPackageId", selMap.get("BANKREQSEQID").toString()));//包序列 ID
            }else {
                tmpRetDetail.respCode ="-1";
                tmpRetDetail.respInfo = "财务系统交易流水号关联映射异常，请检查";
                retAts.writeRetDetail(tmpRetDetail);
                return retAts;
            }
            tmpXElement.addChild(new XElement("TxDate", Format.Date10Format2.format(p_req1944.getBgnDateTime())));//交易日期
            xmlWriter.writeXElement(tmpXElement);
            xmlWriter.writeEndDocument();
            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String txStatus = tmpBkReader.getFirstText("/BOCHKB2E/Head/TxStatus");
                    if ("S".equals(txStatus) || "R".equals(txStatus)) {
                        tmpRetDetail.respCode = "0";
                        tmpRetDetail.respInfo = tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorDesc");
                        tmpRetDetail.reqSeqID = p_req1944.askNumber;
                        if ("R".equals(txStatus) && "E21007".equals(tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorCode"))) {
                            tmpRetDetail.transState = txStatus + "+" + tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorCode");
                            tmpRetDetail.payInfoCode = tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorCode");
                        } else {
                            String readNodePath="/BOCHKB2E/Tx/TransferEnquiryRLY/Requests/Record/";
                            if(tmpStrRet[1].contains("InternalTrans")){
                                readNodePath+="InternalTrans";
                            }else if(tmpStrRet[1].contains("LocalBankTrans")){
                                readNodePath+="LocalBankTrans";
                            }else if(tmpStrRet[1].contains("TeleTransfer")){
                                readNodePath+="TeleTransfer";
                            }
                            /*if (StringHelper.hasAnyChar(tmpBkReader.getFirstText(readNodePath + "/CustRef"))) {
                                tmpRetDetail.reqSeqID = tmpBkReader.getFirstText(readNodePath + "/CustRef");
                            }else {
                                tmpRetDetail.reqSeqID=reqQryForeignCurrSingle.askNumber;
                            }*/
                            tmpRetDetail.transState = tmpBkReader.getFirstText(readNodePath + "/TxStatus");
                            tmpRetDetail.payInfoCode =tmpRetDetail.transState;
                            if (tmpBkReader.getFirstText(readNodePath + "/RejectReason") != null) {
                                tmpRetDetail.respInfo = tmpBkReader.getFirstText(readNodePath + "/RejectReason");
                                tmpRetDetail.payInfoCode = tmpBkReader.getFirstText(readNodePath + "/RejectReason");
                            }
                        }
                    } else {
                        tmpRetDetail.respCode = "-1";
                        tmpRetDetail.respInfo = "错误代码：" + tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorCode") + "，错误信息：" + tmpBkReader.getFirstText("/BOCHKB2E/Head/ErrorDesc");
                    }
                } else {
                    tmpRetDetail.respCode = "-1";
                    tmpRetDetail.respInfo = tmpSbMsg.toString();
                }
            } else {
                tmpRetDetail.respCode = "-1";
                tmpRetDetail.respInfo = tmpStrRet[1];
            }
        } catch (Exception ex) {
            tmpRetDetail = new RetAtsSglDetail();
            tmpRetDetail.respCode = "-1";
            tmpRetDetail.respInfo = ex.getMessage();
            ex.printStackTrace();
        }finally {
            conn.close();
        }
        retAts.writeRetDetail(tmpRetDetail);
        return retAts;
    }

    @Override
    public RetAtsSingleBat d_1908BAT_SglBatPay(ReqSingleBat p_req1908BAT) throws Exception {
        return null;
    }

    @Override
    public RetAtsSingleBat d_1944BAT_QrySglBatPay(ReqQrySingleBat p_req1944BAT) throws Exception {
        return null;
    }
}
